#include <iostream>

using namespace std;

class Solution {
public:
    /**
     * @param num: An integer
     * @return: An integer, the number of ones in num
     */
    int countOnes(int num) {
        int count = 0;
        while(num != 0) {
            count++;
            num = num & (num - 1);
        }

        return count;
    }
};
